﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2016-2018 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Folding map</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="Crop and mask filter on an ol map or layer." />
  <meta name="keywords" content="ol3, filter, effect, fold, folding, map, canvas" />

  <link rel="stylesheet" href="../style.css" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <style>
    #map {
      background: none;
      border: 0;
      transition: all 0.6s ease-in-out;
    }
    #map.foldup {
      transform: scaleX(0.005);
    }
    label {
      display: inline-block;
      width:5em;
      text-align: right;
    }
    input {
      width:3em;
    }
  </style>

</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Folding map</h1>
  </a>
  <div class="info">
    <i>ol.filter.Fold</i> creates a folding effect on the map.
    <br/>
    The <i>Fold up!</i> button adds a CSS3 transition effect on the map to fold/unfold the map.
  </div>

  <!-- Map div -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options" >
    <h2>Options:</h2>
    <ul>
      <li>
        <label>fold: </label>
        <input id="foldx" type="number" value="8" min="1" onchange="setFilter()" /> x
        <input id="foldy" type="number" value="4" min="1" onchange="setFilter()" />
      </li>
      <li>
        <label>margin:</label> <input id="margin" type="number" min="0" value="8" onchange="setFilter()" />
      </li>
      <li>
        <label>padding:</label> <input id="padding" type="number" min="0" value="8" onchange="setFilter()" />
      </li>
      <li>
        <label>fsize:</label> 
        <input id="fsizex" type="number" min="0" value="8" onchange="setFilter()" /> x
        <input id="fsizey" type="number" min="0" value="10" onchange="setFilter()" />
      </li>
      <button onclick="$('#map').toggleClass('foldup')">Fold up!</button>
    </ul>
  </div>

  <script type="text/javascript">

    var stamen = new ol.layer.Geoportail('ORTHOIMAGERY.ORTHOPHOTOS')
    var labels = new ol.layer.Geoportail('GEOGRAPHICALNAMES.NAMES')

    // The map
    var map = new ol.Map({
      target: 'map',
      view: new ol.View({
        zoom: 11,
        center: [184410, 6483281]
      }),
      controls: [],
      layers: [ stamen, labels ]
    });

    function setFilter () {
      for (var i=0; i<2; i++) {
        filter[i].set('fold', [ Math.max(1, parseInt($('#foldx').val())), Math.max(1, parseInt($('#foldy').val())) ]);
        filter[i].set('margin', Math.max(0, parseInt($('#margin').val())));
        filter[i].set('padding', Math.max(0, parseInt($('#padding').val())));
        filter[i].set('fsize', [Math.max(0, parseInt($('#fsizex').val())), Math.max(0, parseInt($('#fsizey').val()))]);
      }
    }

    // Fold filter
    var filter = [
      new ol.filter.Fold({ fill: true, shadow: false }),
      new ol.filter.Fold({})
    ];
    stamen.addFilter(filter[0]);
    labels.addFilter(filter[1]);
    // map.addFilter(filter);
    setFilter();

  </script>

</body>
</html>